package com.yuejie.user.manager.impl;

import java.util.List;
import java.util.Map;

import com.yuejie.db.DBConnection;
import com.yuejie.user.manager.LoginManager;
import com.yuejie.util.MD5Util;

/**
 * @ClassName: LoginManagerImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author husongbo
 * @date 2012-7-3 下午04:12:32
 * 
 */

public class LoginManagerImpl implements LoginManager {
	
	DBConnection db = null;
	
	public LoginManagerImpl()
	{
		db = new DBConnection();
	}
	
	public String login(String psn_account, String psn_password) throws Exception
	{
		String result = "success";
		String password = "";
		Object[] params = new Object[]{psn_account};
		List<Map<String, Object>> list = db.querySMSInfo(SELECT_SQL, params);
		if(list == null || list.size() == 0)
		{
			result = "invailduser";
		}
		else
		{
			Map<String, Object> map = list.get(0);
			password = (String)map.get("psn_password");
			String paramPass =  MD5Util.MD5(psn_password);
			
			if(!password.equals(paramPass))
			{
				result = "invaildpassword";
			}
		}
		
		db.close();
		
		return result;
		
	}
	
	private final static String SELECT_SQL = "SELECT PSN_ACCOUNT, PSN_PASSWORD FROM PERSON WHERE PSN_ACCOUNT = ?";

}
